[android] Is it possible to receive SMS message on appWidget?

Posted by cappuccino on Stack Overflow See other posts from Stack Overflow or by cappuccino
Published on 2010-05-03T09:06:44Z Indexed on 2010/05/03 9:08 UTC
Read the original article Hit count: 320

Filed under:

[Android]

Hi, everyone.

Is it possible to receive SMS message on appWidget?

I saw android sample soucrce(API Demos). In API Demos, ExampleAppWidgetProvider class extends AppWidgetProvider, not Activity.

So, I guess it is impossible to regist SMS Receiver like this,

rcvIncoming = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                Log.i("telephony", "SMS received");
                Bundle data = intent.getExtras();
                if (data != null) {
                    // SMS uses a data format known as a PDU
                    Object pdus[] = (Object[]) data.get("pdus");
                    String message = "New message:\n";
                    String sender = null;
                    for (Object pdu : pdus) {
                        SmsMessage part = SmsMessage.createFromPdu((byte[])pdu);
                        message += part.getDisplayMessageBody();
                        if (sender == null) {
                            sender = part.getDisplayOriginatingAddress();
                        }
                    }

                    Log.i(sender, message);

                }
            }
        };
        registerReceiver(rcvIncoming, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));

My goal is to receive SMS message on my custom appWidget.

any help would be appreciated!!

© Stack Overflow or respective owner

Related posts about android